/*
 * @Author: WangShuai 1830773767@qq.com
 * @Date: 2025-06-09 21:08:09
 * @LastEditors: WangShuai 1830773767@qq.com
 * @LastEditTime: 2025-06-10 11:35:39
 * @FilePath: \vue3_admin_template\project\src\api\acl\role\index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import request from '@/utils/request'
import { RoleData, RoleResponseData, MenuResponseData } from './type'
//角色管理模块接口
enum API {
  //获取全部职位接口
  ALLROLE_URL = '/admin/acl/role',
  //添加新的职位接口
  ADDROLE_URL = '/admin/acl/role/save',
  //更新已有的职位为接口
  UPDATEROLE_URL = '/admin/acl/role/update',
  //删除职位接口
  REMOVE_URL = '/admin/acl/role/remove',
  //根据职位ID获取菜单数据
  ALLPERMISSION_URL = '/admin/acl/permission/toAssign/', //roleId
  //给相应的职位分配权限
  SETPERMISSION_URL = '/admin/acl/permission/doAssign/', //roleId post permissionId
}
//获取全部角色
export const reqAllRoleList = (page: number, limit: number, roleName: string) =>
  request.get<any, RoleResponseData>(
    API.ALLROLE_URL + `/${page}/${limit}/?roleName=${roleName}`,
  )

//添加职位于更新已有职位方法
export const reqAddOrUpdateRole = (data: RoleData) => {
  if (data.id) {
    //更新
    return request.put<any, any>(API.UPDATEROLE_URL, data)
  } else {
    //添加
    return request.post<any, any>(API.ADDROLE_URL, data)
  }
}
//删除职位信息
export const reqRemove = (roleId: number) =>
  request.delete<any, any>(API.REMOVE_URL + `/${roleId}`)
//获取全部菜单与按钮权限数据
export const reqAllMenuList = (roleId: number) =>
  request.get<any, MenuResponseData>(API.ALLPERMISSION_URL + `${roleId}`)
//给相应的职位分配权限
export const reqSetPermission = (roleId: number, permissionId: number[]) =>
  request.post<any, MenuResponseData>(
    API.SETPERMISSION_URL + `?roleId=${roleId}&permissionId=${permissionId}`,
  )
